﻿using System;
using System.Linq;
using Service;

namespace ECommerce.Controls
{
	public partial class SiteHeader : BaseUserControl
	{
		private IShoppingCartItemService _ShoppingCartItemService;

		protected void Page_Load(object sender, EventArgs e)
		{
		}


		protected void Page_PreRender(object sender, EventArgs e)
		{
			this.LAboutUsText.Text = GetLocalResourceString("ECommerce.AboutUs.Text");
			this.LShoppingGuideText.Text = GetLocalResourceString("ECommerce.ShoppingGuide.Text");
			this.LHoursLabel.Text = GetLocalResourceString("ECommerce.Hours.Label");
			this.LHoursText.Text = GetLocalResourceString("ECommerce.Hours.Text");
			this.LTelLabel.Text = GetLocalResourceString("ECommerce.Tel.Label");
			this.LTelText.Text = GetLocalResourceString("ECommerce.Tel.Text");

			GetMyShoppingCartCount();
		}

		private void GetMyShoppingCartCount()
		{
			if(SiteContext.Current == null || SiteContext.Current.User == null)
			{
				return;
			}

			var userID = new Guid(SiteContext.Current.User.ProviderUserKey.ToString());

			if(_ShoppingCartItemService == null)
			{
				_ShoppingCartItemService = new ShoppingCartItemService();
			}

			var count = 0;
			var cartItems = _ShoppingCartItemService.GetShoppingCartItemByUser(userID);

			if (cartItems != null && cartItems.Count > 0)
			{
				count = cartItems.Count;
			}

			HyperLinkMyCart.Text = GetLocalResourceString("ECommerce.MyShoppingCart") + "(" + count.ToString() + ")";
		}

	}
}